﻿using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Logging;
using Quickuse.Logging.HttpLogger;
using System;
using System.Collections.Generic;
using System.Text;

namespace Quickuse.Logging
{
    /// <summary>
    /// HttpLoggerExtensions
    /// </summary>
    public static class HttpLoggerExtensions
    {
        /// <summary>
        /// AddHttp
        /// </summary>
        /// <param name="builder">builder</param>
        /// <returns></returns>
        public static ILoggingBuilder AddHttp(this ILoggingBuilder builder)
        {

            builder.Services.TryAddSingleton<ILoggingConfiguration, LoggingConfiguration>();
            builder.Services.TryAddSingleton<IHttpLoggerSettings, HttpLoggerSettings>();
            builder.Services.TryAddSingleton<HttpLoggerProcessor, HttpLoggerProcessor>();
            builder.Services.AddSingleton<ILoggerProvider, HttpLoggerProvider>();

            return builder;
        }

        /// <summary>
        /// AddHttp
        /// </summary>
        /// <param name="builder">builder</param>
        /// <param name="configuration">configuration</param>
        /// <returns></returns>
        public static ILoggingBuilder AddHttp(this ILoggingBuilder builder, IConfiguration configuration)
        {
            builder.Services.TryAddSingleton<ILoggingConfiguration, LoggingConfiguration>();
            builder.Services.TryAddSingleton<IConfiguration>(configuration);
            builder.Services.TryAddSingleton<IHttpLoggerSettings, HttpLoggerSettings>();
            builder.Services.TryAddSingleton<HttpLoggerProcessor, HttpLoggerProcessor>();
            builder.Services.AddSingleton<ILoggerProvider, HttpLoggerProvider>();

            return builder;
        }
    }
}
